
<template>
  <el-config-provider :locale="locale">
    <router-view></router-view>
  </el-config-provider>
  <!-- <router-view /> -->
  <messageDrawer></messageDrawer>
</template>
<script setup lang="ts">
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import messageDrawer from "@/components/messageDrawer.vue";
import { useMain,store  } from "@/store/index";
const useMainStore = useMain(store);//pinia

// import DevicePixelRatio from './utils/devicePixelRatio'
let locale = zhCn
// new DevicePixelRatio().init()

// useMainStore.updatedSystemNotice(false);//关闭弹窗

// window.addEventListener('beforeunload', () => {
//   console.log('关闭');

// });

onMounted(() => {
  window.addEventListener('beforeunload', e => beforeunloadHandler())
window.addEventListener('unload', e => unloadHandler())
})


let beforeUnloadTime = ref(0);
const beforeunloadHandler = ()=>{
  beforeUnloadTime.value = new Date().getTime();
}

const unloadHandler =()=>{
  let unloadTime = new Date().getTime() - beforeUnloadTime.value;
  //判断是窗口关闭还是刷新
  if (unloadTime <= 5) {
    // console.log('关闭窗口');
    useMainStore.mqtt_close();//断开MQTT
  }else{
    // console.log('刷新');
    
  }
}
</script>
<style scoped>
#app {
  height: 100%;
}
</style>
